﻿@using DCMS.Web.Extensions;
@using DCMS.Web.Framework.UI;
@using DCMS.ViewModel.Models.Products;

@model BrandListModel
@*<div class="row">

        <div class="col-md-12">

            <div class="input-group mb5">
                <input type="text" id="txt_SearchStr" class="form-control" placeholder="品牌关键字...">
                <span class="input-group-btn">
                    <button id="btn_query" type="button" class="btn btn-primary" style="border:1px solid #dddddd;"><span class="glyphicon glyphicon-search"></span> 搜索</button>
                </span>
            </div>

            <table class="table table-striped table-hover">
                <thead>
                    <tr>
                        <th class="bs-checkbox " style="text-align: center; vertical-align: middle; width: 36px; " data-field="id"><div class="th-inner "><input name="btSelectAll" type="checkbox"></div></th>
                        <th data-field="Name"><div class="th-inner">品牌名称</div></th>
                        <th data-field="DisplayOrder" class="text-center"><div class="th-inner">排序</div></th>
                        <th data-field="Status" data-align="center" class="text-center"><div class="th-inner">状态</div></th>
                        <th data-field="Operator" data-align="center" class="text-right"><div class="th-inner">操作</div></th>
                    </tr>
                </thead>
                <tbody>
                    @{
                        int index = 0;
                        foreach (var brand in Model.Items)
                        {
                            <tr>
                                <td class="bs-checkbox ">
                                    <input data-index="@index" name="btSelectItem" class="btSelectItem" type="checkbox" value="@brand.Id">
                                </td>
                                <td>@brand.Name</td>
                                <td class="text-center">@brand.DisplayOrder</td>
                                <td class="text-center">
                                    <span class="label label-success">@(brand.Status? "正常" : "锁定")</span>
                                </td>
                                <td class="text-right">
                                    <a class="btn btn-sm btn-primary btn_addselect_Brand" data-id="@brand.Id" data-name="@brand.Name" href="javascript:;" title="选择"><i class="glyphicon glyphicon-pencil mr5"></i> 选择</a>
                                </td>

                            </tr>
                            index++;
                        }

                    }
                </tbody>
            </table>
           @{
                                var pager = Html.Pager(Model.PagingFilteringContext).QueryParam("pagenumber");
                            }

                            @if (!pager.IsEmpty())
                            {
                                <div class="fixed-table-pagination" style="display: block;">
                                    @Html.Raw(pager.ToString())
                                </div>
                            }
        </div>
    </div>*@

<div class="row">
    <div class="col-md-12">
        <div class="input-group mb5">
            <input type="text" id="txt_SearchBrandStr" class="form-control" placeholder="品牌关键字..." onkeydown="if(event.keyCode==13){event.keyCode=0;event.returnValue=false;}">
            <span class="input-group-btn">
                <button id="btn_PopBrandQuery" type="button" class="btn btn-primary" style="border:1px solid #dddddd;"><span class="glyphicon glyphicon-search"></span> 搜索</button>
            </span>
        </div>
        <table class="table table-striped table-hover" id="brand_datatable"></table>
    </div>
</div>

<script type="text/javascript">


    $(function () {

        //供应商列表
        $("#brand_datatable").bootstrapTable({
            url: "/Brand/AsyncList",
            method: 'get',
            striped: true,
            cache: false,
            pagination: true,
            queryParams: function (params) {
                var temp =
                {
                    key: $("#txt_SearchBrandStr").val(),
                    pageSize: params.limit,
                    pageIndex: (params.offset / params.limit)
                };
                return temp;
            },
            sidePagination: "server",
            idField: 'Id',
            pageNumber: 1,
            pageSize: 10,
            search: false,
            strictSearch: true,
            showRefresh: false,
            clickToSelect: false,
            uniqueId: "Id",
            showToggle: false,
            cardView: false,
            detailView: false,
            columns: [
                { checkbox: true },
                { field: 'id', visible: false },
                { field: 'Name', title: '品牌名称' },
                { field: 'DisplayOrder', title: '排序' },
                {
                    field: 'Status', title: '状态', formatter: function (value, row, index) {
                        if (value == true) {
                            return "启用";
                        }
                        if (value == false) {
                            return "禁用";
                        }
                    }
                },
                {
                    field: 'operate', title: '操作', align: 'center', width: '100',
                    events: operateEventsPopBrand,
                    formatter: function (value, row, index) {
                        return [
                            '<button type="button" class="btn btn-sm btn-info rowSelect" data-id="" data-target=""><i class="fa fa-pencil-square-o"></i>&nbsp;选择</button>'
                        ].join('');
                    }
                }
            ],
            onPageChange: function (number, size) {
                m_pagerow = (number - 1) * size;
            },
            onLoadSuccess: function (data) {
                //console.log('load');
            },
            onLoadError: function (a, b) {  //加载失败时执行
                console.log('加载数据失败');
            }
        });
        //查询
        $("#btn_PopBrandQuery").on('click', function () {
            var keys = $("#btn_PopBrandQuery").val();
            $("#brand_datatable").bootstrapTable('refresh');
        });
    });
</script>